package com.emerald.jms;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;

public class PointToPointMessaging {

	public enum SenderReceiver {
		sender, receiver

	}

	public class UserSettings {
		public SenderReceiver senderReceiver;
		public String queueName;

	}

	private static Options options = null; // Command line options

	private static final String RECEIVER_OPTION = "receiver";
	private static final String SENDER_OPTION = "sender";
	private static final String QUEUENAME_OPTION = "queueName";
	private static final String QUEUENAME_DEFAULT = "test.Queue1";

	static {
		options = new Options();
		options.addOption(RECEIVER_OPTION, false, "Launch as a receiver");
		options.addOption(SENDER_OPTION, false, "Launch as a sender");
		Option option = new Option(QUEUENAME_OPTION, true, "QueueName");
		option.setType(String.class);
		options.addOption(option);

	}

	/**
	 * @param args
	 */
	public static void main(String args) {
		// TODO Auto-generated method stub

	}

	public UserSettings parseCommandLine(String... commandLineString) {

		CommandLineParser commandLineParser = new PosixParser();

		CommandLine commandLine = null;

		try {
			commandLine = commandLineParser.parse(options, commandLineString);
		} catch (ParseException e) {
			System.out.println(e.getMessage());
			System.out.println("USAGE:");
			for (Object optionObject : options.getOptions()) {
				Option option = (Option) optionObject;
				String opt = option.getOpt();
				String description = option.getDescription();
				System.out.println("\t -" + opt + " " + description);
			}
		}

		UserSettings userSettings = new UserSettings();

		if (commandLine.hasOption(RECEIVER_OPTION))
			userSettings.senderReceiver = SenderReceiver.receiver;
		else
			userSettings.senderReceiver = SenderReceiver.sender;

		if (commandLine.hasOption(QUEUENAME_OPTION))
			userSettings.queueName = commandLine
					.getOptionValue(QUEUENAME_OPTION);
		else {
			userSettings.queueName = QUEUENAME_DEFAULT;
		}

		return userSettings;
	}

	public void Reciever() {

	}

	public void Sender() {

	}

}
